<?php

namespace App\EventHandler;

use App\Event\Event;
use App\Logic\Order\OrderService;
use EasySwoole\EasySwoole\Logger;

class OrderAutoSettleHandler extends HandlerBase
{
    function handle()
    {
        Event::getInstance()->set(Event::EVENT_ORDER_AUTO_SETTLE, function (...$args) {
            Logger::getInstance()->info('处理每日结算事件');
            try {
                list($data) = func_get_args();
                OrderService::getInstance()->jobOrderAutoSettle($data['id'], $data['date']);
                return [
                    'result'  => true,
                    'message' => ''
                ];
            } catch (\Throwable $e) {
                return [
                    'result'  => false,
                    'message' => $e,
                ];
            }
        });
    }

}
